package com.test.exception.other;

import java.io.Serializable;

public class Result implements Serializable {
    private ResultCode code;
    private String msg;
    private Object data;

    public Result() {
    }

    public Result(ResultCode code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static Result success() {
        Result result = new Result();
        result.setCode(ResultCode.SUCCESS);
        return result;
    }

    public static Result success(Object data) {
        Result result = new Result();
        result.setCode(ResultCode.SUCCESS);
        result.setData(data);
        return result;
    }

    public static Result fail(ResultCode resultCode) {
        Result result = new Result();
        result.setCode(resultCode);
        return result;
    }

    public static Result fail(ResultCode resultCode, Object data) {
        Result result = new Result();
        result.setCode(resultCode);
        result.setData(data);
        return result;
    }


    public ResultCode getCode() {
        return code;
    }

    public void setCode(ResultCode code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "Result{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }

    public static void main(String[] args) {
        System.out.println(Result.success("测试"));
    }
}
